package nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class LargeMappedFiles {

	static int length = 0x80FFFFF;

	public static void main(String[] args) throws Exception {
		MappedByteBuffer mbb = new RandomAccessFile("test.dat", "rw")
				.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);

		for (int i = 0; i < length; i++) {
			mbb.put((byte) 'x');
		}

		System.out.println("finished writing");

		for (int i = length / 2; i < length / 2 + 6; i++) {
			System.out.println((char) mbb.get(i));
		}
	}
}
